package com.minelx.scriptbuilder.parse.matcher;

import com.minelx.sequence.IStringScanner;
import com.minelx.sequence.ReturnMatcher;
import com.minelx.scriptbuilder.script.IVariable;
import com.minelx.scriptbuilder.script.ScriptContext;

public class GlobalVariableMatcher implements ReturnMatcher<IVariable, IStringScanner> {

	private final ScriptContext context;

	public GlobalVariableMatcher(ScriptContext context) {
		this.context = context;
	}

	@Override
	public boolean isMatch(IStringScanner scanner) {
		return scanner.existsIf(Character::isAlphabetic);
	}

	@Override
	public IVariable onMatched(IStringScanner scanner) {
		String variableName = scanner.nextPage();
		return context.variable(variableName);
//		 FIXME 2021/3/26  wait for me!!!
//		return new Variable(context, variableName, AttributeDecorator.dot(context, variableName));
	}
}
